/*
 * @Author       : xxsoftware
 * @Date         : 2023-07-03 22:26:48
 * @LastEditors  : xxsoftware
 * @LastEditTime : 2023-07-03 22:26:51
 * @FilePath     : \site\script\deploy.js
 * @Description  :
 */
import { spawn } from 'child_process';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);

const __dirname = dirname(__filename);
const run = async (command, path) => {
    //cmd表示命令，args代表参数，如 rm -rf  rm就是命令，-rf就为参数
    const [cmd, ...args] = command.split(' ');
    return new Promise((resolve, reject) => {
        const app = spawn(cmd, args, {
            cwd: path, //执行命令的路径
            stdio: 'inherit', //输出共享给父进程
            shell: true //mac不需要开启，windows下git base需要开启支持
        });
        //执行完毕关闭并resolve
        app.on('close', resolve);
    });
};

run('deploy.sh', resolve(__dirname, '../'));
